package com.mdlib.helper.module.send.profile.fragments;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.ljlib.help.R;
import com.mdlib.helper.base.BaseTitleFragment;
import com.mdlib.helper.ui.adapter.GenericViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * 作者：HQY on 16/12/19 13:29
 * 邮箱：hqy_xz@126.com
 */

public class SendBuyFragment extends BaseTitleFragment {


    @Bind(R.id.tab_send_buy)
    TabLayout mTabSendBuy;
    @Bind(R.id.vp_send_buy_pager)
    ViewPager mVpSendBuyPager;

    private SendBuyOngFragment mSendBuyOngFragment;
    private SendBuySuccessFragment mSendBuySuccessFragment;

    private FragmentPagerAdapter vicinityAdapter;

    private List<Fragment> listFragment;

    private List<String> titlFragment;


    public static SendBuyFragment newInstance() {
        return new SendBuyFragment();
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.fragment_send_buy;
    }

    @Override
    protected void initView(View rootView) {
        super.initView(rootView);
        setTitle(R.string.me_tv_buy, R.color.white)
                .setTitleBgColor(R.color.generic_view_bg)
                .setImgLeftListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        removeFragment();
                    }
                });
        init();
    }

    private void init() {
        mSendBuyOngFragment = new SendBuyOngFragment();
        mSendBuySuccessFragment = new SendBuySuccessFragment();


        listFragment = new ArrayList<>();
        listFragment.add(mSendBuyOngFragment);
        listFragment.add(mSendBuySuccessFragment);

        titlFragment = new ArrayList<>();
        titlFragment.add(getActivity().getResources().getString(R.string.buy_tv_ongoing));
        titlFragment.add(getActivity().getResources().getString(R.string.buy_tv_success));

        mTabSendBuy.setTabMode(TabLayout.MODE_FIXED);

        mTabSendBuy.addTab(mTabSendBuy.newTab().setText(titlFragment.get(0)));
        mTabSendBuy.addTab(mTabSendBuy.newTab().setText(titlFragment.get(1)));

        vicinityAdapter = new GenericViewPagerAdapter(getActivity().getSupportFragmentManager(), listFragment, titlFragment);
        mVpSendBuyPager.setAdapter(vicinityAdapter);
        mTabSendBuy.setupWithViewPager(mVpSendBuyPager);
    }


}
